class Solution(object):
    def isPowerOfThree(self, n):
        """
        :type n: int
        :rtype: bool
        """
        import math
        if n <= 0:
            return False
        max3Power = int(pow(3, int(math.log(0x7fffffff) / math.log(3))))
        if max3Power % n:
            return False
        else:
            return True